{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input class="layui-input" type="text" placeholder="请输入节点名称" name="title" style="width: 195px;height: 30px;">
            </div>
            <button class="layui-btn layui-btn-small" type="submit"><i class="fa fa-search" aria-hidden="true"></i>搜索</button>
        </div>
    </form>
    <fieldset class="layui-elem-field site-demo-button" style="margin-top: 20px;">
        <!--<legend>六种按钮主题</legend>-->
        <div style="margin: 4px 4px 4px">
            <button data="0" class="layui-btn layui-btn-primary add" style="background-color: #a191ff;"><i class="fa fa-plus" aria-hidden="true"></i>添加</button>
            <button class="layui-btn layui-btn-warm disable"><i class="fa fa-plus" aria-hidden="true"></i>禁用</button>
            <button class="layui-btn enable"><i class="fa fa-plus" aria-hidden="true">恢复</i></button>
            <button class="layui-btn layui-btn-danger del"><i class="fa fa-plus" aria-hidden="true"></i>删除</button>
            <button class="layui-btn layui-btn-normal recycled"><i class="fa fa-plus" aria-hidden="true"></i>回收站</button>
            <button class="layui-btn layui-btn-normal rebuild"><i class="fa fa-plus" aria-hidden="true"></i>重建树</button>
        </div>
    </fieldset>

    <table class="layui-table" lay-filter="menuList" lay-skin="line">
        <thead>
        <tr>
            <th lay-data="{field:'#', width:5, sort: true}">#</th>
            <th lay-data="{field:'title', width:80}">菜单名</th>
            <th lay-data="{field:'control', width:80, sort: true}">菜单链接</th>
            <th lay-data="{field:'#', width:80, sort: true}">操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach name="menu" key="k" item="vo"}
        <tr>
            <td>{$k+1}</td>
            <td>{$vo.line}{$vo.title}</td>
            <!--<td>{:url($vo.url)}</td>-->
            <td>{$vo.url}</td>
            <td>
                <a data="{$vo.id}" class="layui-btn layui-btn-mini add"><i class="fa fa-plus-square-o" aria-hidden="true"></i></a>
                <a data="{$vo.id}" class="layui-btn layui-btn-mini layui-btn-normal edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
                <a data="{$vo.id}" class="layui-btn layui-btn-danger layui-btn-mini del"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
                <if condition="$vo['pid']">
                    <a data="{$vo.id}" class="layui-btn  layui-btn-warm layui-btn-mini see"><i class="fa fa-search" aria-hidden="true"></i>&nbsp;查看操作</a>
                </if>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    var table = layui.table,
        $ =layui.jquery,
        form = layui.form;

    $(".add").click(function () {
        var id = $(this).attr("data");
        $.get("{:url('Menu/addMenu')}",{id:id},function (data) {
            if (data.status == "error"){
                layer.msg(data.msg,{icon:5});
                return ;
            }
            layer.open({
                titel : "添加节点",
                type : 1 ,
                area : ['500px'],
                content : data,
            });
        })
    });
    //编辑菜单
    $('.edit').click(function () {
        var id = $(this).attr('data');
        var url = "{:url('Menu/editMenu')}";

        $.get(url, {id: id}, function (data) {
            if (data.status == 'error') {
                layer.msg(data.msg, {icon: 5});
                return;
            }

            layer.open({
                title: '编辑菜单',
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                //area: ['500px'], //宽高
                content: data,
            });
        })
    });

    //查看opt
    $('.see').click(function () {
        var id = $(this).attr('data');
        var url = "{:url('Menu/viewOpt')}";
        $.get(url, {id: id}, function (data) {
            if (data.status == 'error') {
                layer.msg(data.msg, {icon: 5});
                return;
            }
            layer.open({
                title: '查看三级菜单',
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['80%', '70%'], //宽高
                content: data,
            });
        })
    });

    //删除
    $('.del').click(function () {
        var id = $(this).attr('data');
        var url = "{:url('Menu/deleteMenu')}";
        layer.confirm('确定删除吗?', {
            icon: 3,
            skin: 'layer-ext-moon',
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.post(url, {id: id}, function (data) {
                if (data.status == 'error') {
                    layer.msg(data.msg, {icon: 5});//失败的表情
                    return;
                } else {
                    layer.msg(data.msg, {
                        icon: 6,//成功的表情
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        location.reload();
                    });
                }
            })
        });
    });
    //重建树图
    //重建树图
    $('.rebuild').click(function () {
        var parent = '-1';
        var left = '0';
        var url = "{:url('/aa.php')}";
        layer.confirm('确定重建树吗?', {
            icon: 3,
            skin: 'layer-ext-moon',
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.post(url, {parent: parent,left:left}, function (data) {
                if (data.status == 'error') {
                    layer.msg(data.msg, {icon: 5});//失败的表情
                    return;
                } else {
                    layer.msg(data.msg, {
                        icon: 6,//成功的表情
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        //location.reload();
                    });
                }
            })
        });
    });
    //重建树图
    $('.rebuild11').click(function () {
        var parent = '-1';
        var left = '0';
        var url = "{:url('/aa.php')}";
        $.get(url, {parent: parent,left:left}, function (data) {
            if (data.status == 'error') {
                layer.msg(data.msg, {icon: 5});
                return;
            }
            layer.open({
                title: '',
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['80%', '70%'], //宽高
                content: data,
            });
        })
    });
</script>
{/block}
